package com.example.demo.bean;

import lombok.Getter;
import lombok.Setter;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

@Setter
@Getter
public class PhoneBean implements WritableComparable<PhoneBean> {
    //电话号码
    private String phone;

    //必须要有，反序列化要调用空参构造器
    public PhoneBean() {
    }

    public PhoneBean(String phone) {
        this.phone = phone;
    }

    /**
     * 序列化
     *
     * @param out
     * @throws IOException
     */
    @Override
    public void write(DataOutput out) throws IOException {
        out.writeUTF(phone);
    }

    /**
     * 反序列化
     * 注：字段属性顺序必须一致
     *
     * @param in
     * @throws IOException
     */
    @Override
    public void readFields(DataInput in) throws IOException {
        this.phone = in.readUTF();
    }

    @Override
    public String toString() {
        return phone;
    }

    @Override
    public int compareTo(PhoneBean other) {
        return this.phone.compareTo(other.phone);
    }
}